package com.youchuang.action.admin;

import java.io.File;
import java.text.ParseException;
import java.text.SimpleDateFormat;

import javax.annotation.Resource;

import org.apache.log4j.Logger;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;

import com.youchuang.action.BaseAction;
import com.youchuang.bean.Book;
import com.youchuang.bean.Product;
import com.youchuang.common.Constant;
import com.youchuang.service.AdminService;

/**
 * 管理员添加图书信息
 * 
 * @author Administrator
 *
 */
@Namespace(value = "/admin")
@ParentPackage("shopping-default")
public class InsertBookAction extends BaseAction {

	private static Logger logger = Logger.getLogger(InsertBookAction.class.getSimpleName());

	private String bigcate;
	private String smallcate;
	private String productName;
	private String author;
	private String publishing;
	private long publishTime;
	private String wordNumber;
	private String whichEdtion;
	private String totalPage;
	private long printTime;
	private String printNumber;
	private String isbn;
	private double fixedPrice;
	private double dangPrice;
	private String keyWords;
	private String description;
	private String authorSummary;
	private String catalogue;
	private String productPic;
	private File file;
	private String fileFileName;
	private String fileContentType;
	private String resultnew;
	
	@Resource
	private AdminService adminService;

	@Action(value = "bookInsertAction", results = {
			@Result(name = Constant.SUCCESS, location = "/common/XYTipsWindowClose.jsp") })
	public String execute() throws Exception {
		logger.info("method is execute");

		Book book = new Book();
		book.setAuthor(author);
		book.setPublishing(publishing);
		book.setPublishTime(publishTime);
		book.setWordNumber(wordNumber);
		book.setWhichEdtion(whichEdtion);
		book.setTotalPage(totalPage);
		book.setPrintTime(printTime);
		book.setPrintNumber(printNumber);
		book.setIsbn(isbn);
		book.setAuthorSummary(authorSummary);
		book.setCatalogue(catalogue);
		Product product = new Product();
		product.setProductName(productName);
		product.setFixedPrice(fixedPrice);
		product.setDangPrice(dangPrice);
		product.setKeyWords(keyWords);
		product.setDescription(description);
		product.setProductPic(productPic);
		product.setAddTime(System.currentTimeMillis());

		book.setProduct(product);

		adminService.saveBook(book, bigcate, smallcate, file, fileFileName);
		resultnew = "商品成功插入";

		return Constant.SUCCESS;
	}

	public void setPublishTime(String publishTime) {
		SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
		try {
			this.publishTime = simpleDateFormat.parse(publishTime).getTime();
		} catch (ParseException e) {
			e.printStackTrace();
		}
	}

	public void setPrintTime(String printTime) {
		SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
		try {
			this.printTime = simpleDateFormat.parse(printTime).getTime();
		} catch (ParseException e) {
			e.printStackTrace();
		}
	}

	public String getBigcate() {
		return bigcate;
	}

	public void setBigcate(String bigcate) {
		this.bigcate = bigcate;
	}

	public String getSmallcate() {
		return smallcate;
	}

	public void setSmallcate(String smallcate) {
		this.smallcate = smallcate;
	}

	public String getProductName() {
		return productName;
	}

	public void setProductName(String productName) {
		this.productName = productName;
	}

	public String getAuthor() {
		return author;
	}

	public void setAuthor(String author) {
		this.author = author;
	}

	public String getPublishing() {
		return publishing;
	}

	public void setPublishing(String publishing) {
		this.publishing = publishing;
	}

	public long getPublishTime() {
		return publishTime;
	}

	public void setPublishTime(long publishTime) {
		this.publishTime = publishTime;
	}

	public String getWordNumber() {
		return wordNumber;
	}

	public void setWordNumber(String wordNumber) {
		this.wordNumber = wordNumber;
	}

	public String getWhichEdtion() {
		return whichEdtion;
	}

	public void setWhichEdtion(String whichEdtion) {
		this.whichEdtion = whichEdtion;
	}

	public String getTotalPage() {
		return totalPage;
	}

	public void setTotalPage(String totalPage) {
		this.totalPage = totalPage;
	}

	public long getPrintTime() {
		return printTime;
	}

	public void setPrintTime(long printTime) {
		this.printTime = printTime;
	}

	public String getPrintNumber() {
		return printNumber;
	}

	public void setPrintNumber(String printNumber) {
		this.printNumber = printNumber;
	}

	public String getIsbn() {
		return isbn;
	}

	public void setIsbn(String isbn) {
		this.isbn = isbn;
	}

	public double getFixedPrice() {
		return fixedPrice;
	}

	public void setFixedPrice(double fixedPrice) {
		this.fixedPrice = fixedPrice;
	}

	public double getDangPrice() {
		return dangPrice;
	}

	public void setDangPrice(double dangPrice) {
		this.dangPrice = dangPrice;
	}

	public String getKeyWords() {
		return keyWords;
	}

	public void setKeyWords(String keyWords) {
		this.keyWords = keyWords;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public String getAuthorSummary() {
		return authorSummary;
	}

	public void setAuthorSummary(String authorSummary) {
		this.authorSummary = authorSummary;
	}

	public String getCatalogue() {
		return catalogue;
	}

	public void setCatalogue(String catalogue) {
		this.catalogue = catalogue;
	}

	public String getProductPic() {
		return productPic;
	}

	public void setProductPic(String productPic) {
		this.productPic = productPic;
	}

	public File getFile() {
		return file;
	}

	public void setFile(File file) {
		this.file = file;
	}

	public String getFileFileName() {
		return fileFileName;
	}

	public void setFileFileName(String fileFileName) {
		this.fileFileName = fileFileName;
	}

	public String getFileContentType() {
		return fileContentType;
	}

	public void setFileContentType(String fileContentType) {
		this.fileContentType = fileContentType;
	}

	public String getResultnew() {
		return resultnew;
	}

	public void setResultnew(String resultnew) {
		this.resultnew = resultnew;
	}

}
